#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using i128 = __int128;
const int N = 1e6 + 5;

void solve() {
    int m, k, g, p;
    cin >> m >> k >> g >> p;
    if (m < 0) m = 0;
    int cnt = 0;
    while (m >= p || k >= 2 || g >= 4) {
        if (m >= p) {
            int buy = m / p;
            cnt += buy;
            k += buy;
            g += buy;
            m -= p * (buy);
        }
        if (k >= 2) {
            int e1 = k / 2;
            cnt += e1;
            g += e1;
            k = k % 2 + e1;
        }
        if (g >= 4) {
            int e2 = g / 4;
            cnt += e2;
            k += e2;
            g = g % 4 + e2;
        }
    }
    cout << cnt << endl;
    return;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    solve();

    return 0;
}